#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<wait.h>

int main()
{
  int pip[2];
  if(pipe(pip)==-1)
  {
    perror("pipe\n");
    exit(-1);
  }
  
  pid_t id = fork();

  if(id<0)
  {
    perror("fork \n");
    exit(-1);
  }
  else if(id ==0)
  {
      close(pip[0]);
      const char *str="Hello i am child course";
      int count=3;
      while(count>0)
      {
        sleep(1);
        count--;
        write(pip[1],(char *)str,strlen(str));
      }
      printf("child course just writing done ,now eixt\n");
  
      exit(-1);
  }
  else 
  {
      close(pip[1]);
  
      char buffer[64];
      while(1)
      {
        buffer[64]=0;
         ssize_t ret =read(pip[0],(char *)buffer,sizeof(buffer)-1);
        if(ret==0)
        {
          
          break;
        }
        else 
        {
            printf("the massage form child course $$%s \n",buffer);
            fflush(stdout);
        }

      }

      int status=0;
      wait(&status);
      printf("course exit......\n");
  }


  return 0;
}
